package org.ezplatform.office.questionnaire.util;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.ezplatform.cloud.common.service.ConfigService;
import org.ezplatform.util.GlobalConstant;
import org.ezplatform.util.JsonUtils;
import org.ezplatform.util.RestClient;
import org.ezplatform.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * 消息推动工具类
 */
@Service
public class SendMsgUtils {
	private final static org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger(SendMsgUtils.class);
	/**
	 * 新问卷卷标题
	 */
	public static final String NEW_TITLE = "新问卷";

	/**
	 * 问卷回退标题
	 */
	public static final String BACK_TITLE = "问卷回退";

	/**
	 * 问卷到期标题
	 */
	public static final String OVER_DUE = "问卷到期";

	/**
	 * 新问卷提醒语句
	 */
	public static final String NEWQUES = "您收到一份新问卷，请尽快完成！";

	/**
	 * hoa推送提醒（新问卷）
	 */
	public static final String NEWQUES_FOR_HOA = "您收到一份新问卷：";
	/**
	 * 回退问卷 提醒语句
	 */
	public static final String REPLY = "您收到一份回退的问卷，请重新提交";

	/**
	 * 回退问卷 提醒语句
	 */
	public static final String OVER_DUE_TITLE = "您有一份问卷截止日期快到了，请及时答卷！";

	/**
	 * hoa推送提醒（回退的问卷）
	 */
	public static final String REPLY_FOR_HOA = "您收到一份回退问卷：";

	/**
	 * 新问卷标志
	 */
	public static final String NEWQUESSTATUS = "1";
	/**
	 * 回退问卷标志
	 */
	public static final String REPLYSTATUS = "2";

	/**
	 * 消息模块id
	 */
	public static final String MODULEID = "a0d6deb501c911e9a61300505683e8cd";

	/**
	 * 消息模块code
	 */
	public static final String MODULECODE = "stdQuestionnaire";

	/**
	 * 导航menu_id
	 */
	public static final String QUES_NAV_ID = "402887f85fe2842c015fe287e3e30004";

	/**
	 * 答卷页面url
	 */
	public static final String QUES_ANSWER_URL = "modules/questionnaire/questionnaire_answer.html";

//	@Autowired
//	private MobileMessageService mobileMessageService;
	
	@Autowired
	private ConfigService configService;
	
	/**
	 * 发送推送
	 * 
	 * @param map
	 *            参数集合 1、type （1新问卷；2回退；） 2、userIds 推送人ddid 3、orgIds 部门ddid
	 *
	 *            4、quesId 问卷id（必填） 5、quesName 问卷名称（必填） 6、quesStarTime 问卷开始时间
	 *            Date（新问卷必填） 6、quesEndTime 问卷结束时间 Date (必填)
	 */
	public void sendMsgToApp(String corpId, String token, Map<String, Object> map, HttpServletRequest request, String userId) {
		try {
			String remindTarget=(String)map.get("remindTarget");
			String userIds = StringUtils.null2String(map.get("userIds"));
			String type = StringUtils.null2String(map.get("type"));
			// 系统设置中“移动端”设置（wxWork,ding,evoPortal）
			String sysNoticeType = getSysImType(corpId, token, "sysImType");
			// 系统设置中“短信提醒”设置（1-启用，0-禁用）
			String sysSMSsetting = getSysImType(corpId, token, "sysSMSsetting");
			sysSMSsetting=StringUtils.isBlank(sysSMSsetting)?"0":sysSMSsetting;
			/*
			 * 1-启用(默认不选中) 2-启用(默认选中) 0-禁用
			 */
			String evoRemindType=getSysImType(corpId, token,"evoRemind");
			evoRemindType=StringUtils.isBlank(evoRemindType)?"0":evoRemindType;
			LOGGER.debug("zhaozy: "+" sysNoticeType-"+sysNoticeType+" sysSMSsetting-"+sysSMSsetting+" evoRemindType-"+evoRemindType);
			LOGGER.error("zhaozy: "+" sysNoticeType-"+sysNoticeType+" sysSMSsetting-"+sysSMSsetting+" evoRemindType-"+evoRemindType);
			if(StringUtils.isEmpty(sysNoticeType) && "0".equals(sysSMSsetting)) {
				return;
			}
			// 应用中心中问卷模块提醒方式设置（sms,mobile）
			String reminderAction = "";
	        Map<String, Object> appInfo = configService.getAppInfoByAppCode("stdQuestionnaire",corpId,token);
	        if(MapUtils.isNotEmpty(appInfo)) {
	          reminderAction = StringUtils.null2String(appInfo.get("reminderAction"));
	        }
	        LOGGER.debug("zhaozy: reminderAction-"+reminderAction);
	        LOGGER.error("zhaozy: reminderAction-"+reminderAction);
	        // 移动端提醒方式开启
	        if (StringUtils.isNotEmpty(sysNoticeType) && reminderAction.contains("mobile") && StringUtils.contains(remindTarget, "Webapp") && !StringUtils.contains(evoRemindType, "0")) {
	        	LOGGER.debug("zhaozy: 移动提醒");
	        	LOGGER.error("zhaozy: 移动提醒");
	        	Map<String, String> msgTypeMap = new HashMap<String, String>();
				Map<String, Object> messageMap = new HashMap<String, Object>();
				
				String message = "";
				String context = "";
				String webUrl = null ;
				try {
					webUrl = GlobalConstant.getFlexOfficeFullPath(null);
					context = convertContextPath(webUrl);
				}catch(Exception e) {
					LOGGER.debug("zhaozy: exception", e);
					LOGGER.error("zhaozy: exception", e);
				}
//				String webUrl = GlobalConstant.getFlexOfficeFullPath(request);
				
				if (StringUtils.isNotEmpty(context) && context.length() >= 1) {
					context = "contextPath=" + context;
				}
				LOGGER.debug("zhaozy: webUrl-"+webUrl);
				LOGGER.error("zhaozy: webUrl-"+webUrl);
				LOGGER.debug("zhaozy: context-"+context);
				LOGGER.error("zhaozy: context-"+context);
				String orgIds = StringUtils.null2String(map.get("orgIds"));
				LOGGER.debug("zhaozy: orgIds-"+orgIds);
				LOGGER.error("zhaozy: orgIds-"+orgIds);
				String messageWebUrl = "";
				if(sysNoticeType.contains("ding")) {
					msgTypeMap.put("DING", "oa");
//					messageWebUrl = GlobalConstant.getConfig("app.mobile.ding.front.url");
					message = getDingMsg(type, map, context, "");
					Map<String, Object> messageContent = new HashMap<String, Object>();
					messageContent.put("oa", JsonUtils.readValue(message));
					messageMap.put("DING", messageContent);
				}
				if(sysNoticeType.contains("wxWork")){
					msgTypeMap.put("WX", "news");
					//String domain = GlobalConstant.getConfig("app.weixin.domain");
//					messageWebUrl = GlobalConstant.getConfig("app.mobile.weixin.front.url");
					message = getWxOrEvoMsg(type, map, context, "", "WX");
					Map<String, Object> messageContent = new HashMap<String, Object>();
					messageContent.put("news", JsonUtils.readValue(message));
					messageMap.put("WX", messageContent);
				}
				if(sysNoticeType.contains("evoPortal")) {
					msgTypeMap.put("MH", "news");
//					messageWebUrl = GlobalConstant.getConfig("app.mobile.menhu.front.url");
					message = getWxOrEvoMsg(type, map, context, "", "MH");
					Map<String, Object> messageContent = new HashMap<String, Object>();
					messageContent.put("news", JsonUtils.readValue(message));
					messageMap.put("MH", messageContent);
				}
				if(sysNoticeType.contains("CoCall")) {
					msgTypeMap.put("COCALL", "news");
//					messageWebUrl = GlobalConstant.getConfig("app.mobile.cocall.front.url");
					message = getWxOrEvoMsg(type, map, context, "", "COCALL");
					Map<String, Object> messageContent = new HashMap<String, Object>();
					messageContent.put("news", JsonUtils.readValue(message));
					messageMap.put("COCALL", messageContent);
				}
				if(sysNoticeType.contains("weLink")) {
					msgTypeMap.put("WLK", "news");
//					messageWebUrl = GlobalConstant.getConfig("app.mobile.wlk.front.url");
					message = getWxOrEvoMsg(type, map, context, "", "WLK");
					Map<String, Object> messageContent = new HashMap<String, Object>();
					messageContent.put("news", JsonUtils.readValue(message));
					messageMap.put("WLK", messageContent);
				}
				LOGGER.debug("zhaozy: 移动提醒开始发送");
	        	LOGGER.error("zhaozy: 移动提醒开始发送");
				SendMsgThread smt = new SendMsgThread(msgTypeMap, messageMap, MODULECODE, corpId, userIds, orgIds, webUrl, "app");
	        	smt.start();
//				mobileMessageService.sendMobileMsg(corpId, MODULECODE, userIds, orgIds, msgTypeMap, messageMap, request);
			}
	        // 短信提醒方式开启
	        if (!"0".equals(sysSMSsetting) && reminderAction.contains("sms") && StringUtils.contains(remindTarget, "SMS")) {
	        	Map<String, String> smsMap = new HashMap<>();
	        	smsMap.put("sender", userId);
	        	smsMap.put("senderOrg", "");
	        	smsMap.put("receiverIds", userIds);
	        	smsMap.put("systemName", "本系统");
	        	smsMap.put("appCode", "stdQuestionnaire");
	        	smsMap.put("sendContent", this.getSmsMsg(type, map));
	        	smsMap.put("corpId", corpId);
				RestClient restClient = new RestClient(true);
				restClient.post("/sms/saveAllPendingSms", token, new HashMap<String, String>(), JsonUtils.writeValueAsString(smsMap));
	        }
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public Map<String, Object> getAppInfoByAppCode(String corpId,String token){
		return configService.getAppInfoByAppCode("stdQuestionnaire",corpId,token);
	}
	
	public String convertContextPath(String serverUrl) {
		String context = "";
		serverUrl = serverUrl.substring(serverUrl.lastIndexOf("//") + 2, serverUrl.length());
		int index = serverUrl.lastIndexOf("/");
		if (index > 0) {
			if (index == serverUrl.length() - 1) {// /在结尾
				context = "";
			} else {
				context = serverUrl.substring(serverUrl.lastIndexOf("/") + 1);
			}
		} else {
			context = "";
		}
		return context;
	}

	/**
	 *
	 * @param paramMap
	 *            String dataId, 推送信息id <br/>
	 *            String msgType, 消息类型，值范围：1-通知（提醒），2-待办，3-待阅，默认：1 <br/>
	 *            String msgTitle, 消息标题 <br/>
	 *            String msgContent, 消息内容 <br/>
	 *            String openMode, 消息打开方式， 不为空则跳转页面，否则跳转模态框 <br/>
	 *            [String menuNavId] , 菜单应用id，在openMode不为空的时候有效(这里默认为问卷navID) <br/>
	 *            String url, 跳转路径 <br/>
	 *            String quesitionnaireId,问卷id <br/>
	 *            String msgReceiver, 消息接收对象，格式：[{类型1:值1}，{类型2:值2}...]，如:
	 *            [{"10":"4028803a650e5a7a01650e7dfd0b005a"}，{"10":"40288724650e489901650e79edff0005"}]
	 *            <br/>
	 *            String userId, 用户id <br/>
	 *            String corpId, 单位id <br/>
	 *            String token TOKEN <br/>
	 */
	public void sendMsgToOffice(Map<String, String> paramMap) {
		Map<String, String> sendMap = new HashMap<>();
		sendMap.put("moduleCode", "questionnaire");
		sendMap.put("moduleId", MODULEID);
		if (StringUtils.isNotBlank(paramMap.get("msgType"))) {
			sendMap.put("msgType", paramMap.get("msgType"));
		} else {
			sendMap.put("msgType", "1");
		}
		sendMap.put("dataId", paramMap.get("quesitionnaireId"));
		sendMap.put("msgFmt", "1");
		sendMap.put("msgLevel", "3");
		sendMap.put("msgSenderType", "10");
		// 消息推送发送者
		sendMap.put("msgSender", paramMap.get("userId"));
		sendMap.put("corpId", paramMap.get("corpId"));
		sendMap.put("msgTitle", paramMap.get("msgTitle"));
		sendMap.put("msgContent", paramMap.get("msgContent"));
		if (StringUtils.isNotBlank(paramMap.get("openMode"))) {
			sendMap.put("openMode", "1");
			sendMap.put("msgLink", "/front/nav/navMenu?menuNavId=" + QUES_NAV_ID + "#" + paramMap.get("url"));
		} else {
			sendMap.put("msgLink", paramMap.get("url"));
		}
		String paramString = "{\"quesitionnaireId\":\"" + paramMap.get("quesitionnaireId") + "\",\"msgtype\":\"" + 1
				+ "\"}";
		sendMap.put("paramString", paramString);
		sendMap.put("msgReceiver", paramMap.get("msgReceiver"));
		ObjectMapper mapper = new ObjectMapper();
		try {
			SendMsgThread smt = new SendMsgThread(paramMap.get("token"), "pc", mapper.writeValueAsString(sendMap));
	     	smt.start();
//	 		RestClient restClient = new RestClient(true);
//			String msg = restClient.post("/system/umc/message/sendmessage", paramMap.get("token"),
//					new HashMap<String, String>(), mapper.writeValueAsString(sendMap));
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
	}
	
	/**
	  * 刪除消息
	  * @param applyRecordId
	  * @param corpId
	  * @param token
	  */
	public void deleteMessage(List<String> dataIds, String corpId, String token) {
		try {
			if(CollectionUtils.isNotEmpty(dataIds)) {
				RestClient restClient = new RestClient(true);
				for(String dataId : dataIds) {
					Map<String, String> params = new HashMap<String, String>();
					params.put("corpId", corpId);
					params.put("dataId", dataId);
					params.put("moduleCode", "questionnaire");
					restClient.post("/system/umc/message/deleteMessages", token , params);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	   * 获取后台设置参数
	   * @param corpId
	   * @param token
	   * @param markType
	   * return (wxWork,ding,evoPortal)
	   */
	public String getSysImType(String corpId, String token, String markType) {
		RestClient restClient = new RestClient(true);
	  	Map<String, String> paramMap = new HashMap<String, String>();
	  	paramMap.put("corpId", corpId);
	  	paramMap.put("mark", markType);
	  	String jsonStr = restClient.get("/system/config/getConfigValue", token, paramMap);
	  	Map<String, Object> result = JsonUtils.readValue(jsonStr);
	  	if(MapUtils.isNotEmpty(result)) {
		  	if("success".equals(result.get("type"))) return String.valueOf(result.get("data"));
	  	}
	  	return "";
	}
	
	/**
	   * 获取钉钉消息体
	   * 
	   */
	private String getDingMsg(String type, Map<String, Object> map, String context, String url) {
		Date closeDate = (Date) map.get("closeDate");
		String pcurlType="pcurl";
		Calendar ca = Calendar.getInstance();
		ca.setTime(closeDate);
		int day = ca.get(Calendar.DAY_OF_MONTH);// 一年中的第几天
		String dayStr = "";
		if (day < 10) {
			dayStr = "0" + day;
		} else {
			dayStr = String.valueOf(day);
		}
		int month = ca.get(Calendar.MONTH) + 1;// 第几个月
		String monthStr = "";
		if (month < 10) {
			monthStr = "0" + month;
		} else {
			monthStr = String.valueOf(month);
		}
		int year = ca.get(Calendar.YEAR);
		String message = "";
		String messageUrl = url + "/mobile/modules/questionnaire/dist/index.html?"+ context + "&time="
				+ new Date().getTime() + "&dd_nav_bgcolor=FF5E97F6#/questionnaire/ques_info/"
				+ map.get("quesId").toString() + "/0";
		String messagepcUrl = url + "/web/dist/modules/questionnaire/questionnaire_answer.html?window&quesitionnaireId="+map.get("quesId").toString();
		if (StringUtils.equals(NEWQUESSTATUS, type)) {
			message = "{\"message_url\":\"" + messageUrl + "\","
					+"\"pcurl\":\"" + messagepcUrl + "\","
					+ "\"head\": {\"bgcolor\":\"4D98C9\",\"text\": \"问卷通知\"}," + "\"body\": {\"title\":\""
					+ NEWQUES + "\"," + "\"form\": [{\"key\": \"问卷标题：\",\"value\": \"" + map.get("quesName")
					+ "\"}" + ",{\"key\":\"截止日期：\",\"value\":\"" + year + "-" + monthStr + "-" + dayStr + "\"}"
					+ "]}}";
		} else if (StringUtils.equals(REPLYSTATUS, type)) {
			//String backReason = StringUtils.null2String(map.get("backReason"));
			message = "{\"message_url\":\"" + messageUrl + "\","
					+"\"pcurl\":\"" + messagepcUrl + "\","
					+ "\"head\": {\"bgcolor\":\"4D98C9\",\"text\": \"问卷通知\"}," + "\"body\": {\"title\":\""
					+ REPLY + "\"," + "\"form\": [{\"key\": \"问卷标题：\",\"value\": \"" + map.get("quesName")
					+ "\"}" + ",{\"key\":\"截止日期：\",\"value\":\"" + year + "-" + monthStr + "-" + dayStr + "\"}"
					//+ ",{\"key\":\"回退原因：\",\"value\":\"" + backReason + "\"}"
					+ "]}}";
		} else if (StringUtils.equals(OVER_DUE, type)) {
			message = "{\"message_url\":\"" + messageUrl + "\","
					+"\"pcurl\":\"" + messagepcUrl + "\","
					+ "\"head\": {\"bgcolor\":\"4D98C9\",\"text\": \"问卷通知\"}," + "\"body\": {\"title\":\""
					+ OVER_DUE_TITLE + "\"," + "\"form\": [{\"key\": \"问卷标题：\",\"value\": \"" + map.get("quesName")
					+ "\"}" + ",{\"key\":\"截止日期：\",\"value\":\"" + year + "-" + monthStr + "-" + dayStr + "\"}"
					+ "]}}";
		}
		return message;
	}
	
	/**
	   * 获取企业微信或者移动平台消息体
	 * @param urlType 
	   * 
	   */
	private String getWxOrEvoMsg(String type, Map<String, Object> map, String context, String url, String sign) {
		String urlType = "WX".equals(sign) ? "url" : "appUrl";
		String pcurlType="pcurl";
		String br = getBR(sign);
		Date closeDate = (Date) map.get("closeDate");
		Calendar ca = Calendar.getInstance();
		ca.setTime(closeDate);
		int day = ca.get(Calendar.DAY_OF_MONTH);// 一年中的第几天
		String dayStr = "";
		if (day < 10) {
			dayStr = "0" + day;
		} else {
			dayStr = String.valueOf(day);
		}
		int month = ca.get(Calendar.MONTH) + 1;// 第几个月
		String monthStr = "";
		if (month < 10) {
			monthStr = "0" + month;
		} else {
			monthStr = String.valueOf(month);
		}
		int year = ca.get(Calendar.YEAR);
		String message = "";
		String messageUrl = url + "/mobile/modules/questionnaire/dist/index.html?"+ context + "&time="
				+ new Date().getTime() + "&dd_nav_bgcolor=FF5E97F6#/questionnaire/ques_info/"
				+ map.get("quesId").toString() + "/0";
		String messagepcUrl = url + "/web/dist/modules/questionnaire/questionnaire_answer.html?window&quesitionnaireId="+map.get("quesId").toString();
		if (StringUtils.equals(NEWQUESSTATUS, type)) {
			if("COCALL".equals(sign)) {
			message = "{\"articles\" : [{" + 
				          "\"title\" : \"问卷通知\\r\\n\"," + 
				          "\"description\" : \"" + NEWQUES + br +
				            "问卷标题：" + map.get("quesName") + br + 
				              "截止日期：" + year + "-" + monthStr + "-" + dayStr +
				          "\"," + 
				          "\"" + urlType + "\" : \"" + messageUrl + "\"," + 
				          "\"" + pcurlType + "\" : \"" + messagepcUrl + "\""+
				        "}]}";
			}else
			message = "{\"articles\" : [{" + 
			          "\"title\" : \"问卷通知\"," + 
			          "\"description\" : \"" + NEWQUES + br +
			            "问卷标题：" + map.get("quesName") + br + 
			              "截止日期：" + year + "-" + monthStr + "-" + dayStr +
			          "\"," + 
			          "\"" + urlType + "\" : \"" + messageUrl + "\"," + 
			          "\"" + pcurlType + "\" : \"" + messagepcUrl + "\""+
			        "}]}";
		} else if (StringUtils.equals(REPLYSTATUS, type)) {
			//String backReason = StringUtils.null2String(map.get("backReason"));
			if("COCALL".equals(sign)) {
			message = "{\"articles\" : [{" + 
				          "\"title\" : \"问卷通知\\r\\n\"," + 
				          "\"description\" : \"" + REPLY + br +
				            "问卷标题：" + map.get("quesName") + br + 
				            "截止日期：" + year + "-" + monthStr + "-" + dayStr +
				            //"回退原因：" + backReason + br + 
				          "\"," + 
				          "\"" + urlType + "\" : \"" + messageUrl + "\"," + 
				          "\"" + pcurlType + "\" : \"" + messagepcUrl + "\""+
				        "}]}";
			}else
			message = "{\"articles\" : [{" + 
			          "\"title\" : \"问卷通知\"," + 
			          "\"description\" : \"" + REPLY + br +
			            "问卷标题：" + map.get("quesName") + br + 
			            "截止日期：" + year + "-" + monthStr + "-" + dayStr +
			            //"回退原因：" + backReason + br + 
			          "\"," + 
			          "\"" + urlType + "\" : \"" + messageUrl + "\"," + 
			          "\"" + pcurlType + "\" : \"" + messagepcUrl + "\""+
			        "}]}";
		} else if (StringUtils.equals(OVER_DUE, type)) {
			if("COCALL".equals(sign)) {
				message = "{\"articles\" : [{" + 
				          "\"title\" : \"问卷通知\\r\\n\"," + 
				          "\"description\" : \"" + OVER_DUE_TITLE + br +
				            "问卷标题：" + map.get("quesName") + br + 
				              "截止日期：" + year + "-" + monthStr + "-" + dayStr +
				          "\"," + 
				          "\"" + urlType + "\" : \"" + messageUrl + "\"," + 
				          "\"" + pcurlType + "\" : \"" + messagepcUrl + "\""+
				        "}]}";
			}else
			message = "{\"articles\" : [{" + 
			          "\"title\" : \"问卷通知\"," + 
			          "\"description\" : \"" + OVER_DUE_TITLE + br +
			            "问卷标题：" + map.get("quesName") + br + 
			              "截止日期：" + year + "-" + monthStr + "-" + dayStr +
			          "\"," + 
			          "\"" + urlType + "\" : \"" + messageUrl + "\"," + 
			          "\"" + pcurlType + "\" : \"" + messagepcUrl + "\""+
			        "}]}";
		}
		return message;
	}
	
	/**
	 * 获取短信消息体
	 * 
	 * @param type
	 * @param map
	 * @return
	 */
	private String getSmsMsg(String type, Map<String, Object> map) {
		Date closeDate = (Date) map.get("closeDate");
		Calendar ca = Calendar.getInstance();
		ca.setTime(closeDate);
		int day = ca.get(Calendar.DAY_OF_MONTH);// 一年中的第几天
		String dayStr = "";
		if (day < 10) {
			dayStr = "0" + day;
		} else {
			dayStr = String.valueOf(day);
		}
		int month = ca.get(Calendar.MONTH) + 1;// 第几个月
		String monthStr = "";
		if (month < 10) {
			monthStr = "0" + month;
		} else {
			monthStr = String.valueOf(month);
		}
		int year = ca.get(Calendar.YEAR);
		String message = "";
		if (StringUtils.equals(NEWQUESSTATUS, type)) {
			message = NEWQUES + "<br>" + "问卷标题：" + map.get("quesName") + "<br>" + "截止日期：" + year + "-" + monthStr + "-"
					+ dayStr;
		} else if (StringUtils.equals(REPLYSTATUS, type)) {
			//String backReason = StringUtils.null2String(map.get("backReason"));
			message = REPLY + "<br>" + "问卷标题：" + map.get("quesName") + "<br>" + "截止日期：" + year + "-" + monthStr + "-" + dayStr;
		} else if (StringUtils.equals(OVER_DUE, type)) {
			message = OVER_DUE_TITLE + "<br>" + "问卷标题：" + map.get("quesName") + "<br>" + "截止日期：" + year + "-" + monthStr
					+ "-" + dayStr;
		}
		return message;
	}
	
	private String getBR(String type) {
		if("MH".equals(type)||"COCALL".equals(type)) {
			return "   ";
		}
		return "<br>";
	}
}
